package com.yj.rabbitClient.qtoq;

import com.rabbitmq.client.*;
import com.yj.rabbitClient.util.RabbitMQUtil;

import java.io.IOException;

/**
 * 消息的消费者
 */
public class Consumer {
    public static void main(String[] args) {
        Connection connection = RabbitMQUtil.getConnection();
        String queueName = "hello";
        try {
            Channel channel = connection.createChannel();
            channel.queueDeclare(queueName,false,false,false,null);
            channel.basicConsume(queueName,new DefaultConsumer(channel){
                @Override
                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {

                    System.out.println("消费方接收到的消息："+new String(body));
                }
            });


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
